<template>
  <div class="owner-card" @click="navigateToDetail">
    <div class="card-header">
      <span class="name">{{ owner.guestname }}</span>
      <span class="status" :class="statusClass">
        {{ owner.status | statusText }}
      </span>
    </div>

    <div class="card-body">
      <div class="info-row">
        <label>电站编号：</label>
        <span>{{ owner.stationno }}</span>
      </div>
      <div class="info-row">
        <label>电站地址：</label>
        <span>{{ owner.addressstring }}</span>
      </div>
      <div class="info-row">
        <label>创建时间：</label>
        <span>{{ owner.createTime | dateFormat }}</span>
      </div>
    </div>

    <div class="card-actions">
      <button class="btn call" @click.stop="$emit('call', owner.phone)">
        <uni-icons type="phone" size="16" /> 拨打
      </button>
      <button 
        class="btn navigate" 
        @click.stop="$emit('navigate', owner.latitude, owner.longitude)"
      >
        <uni-icons type="location" size="16" /> 导航
      </button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    owner: {
      type: Object,
      required: true
    }
  },

  computed: {
    statusClass() {
      return {
        'status-online': this.owner.status === 1,
        'status-offline': this.owner.status === 2,
        'status-pending': this.owner.status === 3
      }
    }
  },

  methods: {
    navigateToDetail() {
      uni.navigateTo({
        url: `/pages/work/PSM/PSDetails/index?id=${this.owner.id}`
      })
    }
  },

  filters: {
    statusText(status) {
      const statusMap = { 1: '在线', 2: '离线', 3: '待定' }
      return statusMap[status] || '未知'
    },
    dateFormat(timestamp) {
      return new Date(timestamp).toLocaleDateString()
    }
  }
}
</script>

<style scoped>
.owner-card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.name {
  font-weight: 500;
  color: var(--text-primary);
}

.status {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}

.status-online { background: #e1f3d8; color: var(--success-color); }
.status-offline { background: #fde2e2; color: var(--danger-color); }
.status-pending { background: #faecd8; color: var(--warning-color); }

.card-body {
  margin-bottom: 12px;
}

.info-row {
  display: flex;
  margin: 8px 0;
  font-size: 14px;
}

.info-row label {
  color: var(--text-regular);
  min-width: 70px;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.call { background: #f0f7ff; color: var(--primary-color); }
.navigate { background: #f5f5f5; color: var(--text-regular); }
</style>